package com.example.demo.controller;

import ch.qos.logback.core.util.StringUtil;
import com.example.demo.constant.Constants;
import com.example.demo.model.UserInfo;
import com.example.demo.service.UserService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/userlogin")
    public boolean userlogin(String userName, String password, HttpSession httpSession){
        if(StringUtil.isNullOrEmpty(userName)||StringUtil.isNullOrEmpty(password)){
            return false;
        }
        UserInfo userInfo=userService.queryusername(userName);
        log.info("username对象数据 {}",userInfo);
        if(userInfo==null)return false;
        if(userInfo!=null&&userInfo.getPassword().equals(password)){
            httpSession.setAttribute(Constants.SESSION_USER,userInfo);
            return true;
        }
        return false;
    }
}
